//
//  DBJIllTypeMinceViewController.m
//  DBJ
//
//  Created by Captain_czq on 16/11/15.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "DBJIllTypeMinceViewController.h"
#import <MJRefresh.h>
#import "DBJIllTypeModel.h"
#import <SVProgressHUD.h>
@interface DBJIllTypeMinceViewController ()

/* 定义model数组 */
@property(nonatomic,strong)NSArray<DBJIllTypeModel *> *jsonList;

@end

@implementation DBJIllTypeMinceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

-(instancetype)init
{
    if (self = [super init]) {
//        [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
//        [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
//        [SVProgressHUD setBackgroundColor:DBJColor];
//        [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
//        [SVProgressHUD setMinimumDismissTimeInterval:1.0];
//        
//        [SVProgressHUD showSuccessWithStatus:@"拼命加载中....."];
        [DBJTools dbjShowSVTitle:@"拼命加载中...." andTime:0.8];
    }
    return self;
}
-(void)dbjSetupSubviews{
    
    [super dbjSetupSubviews];
    self.view.backgroundColor=[UIColor whiteColor];
    //调用设置表头的方法
    [self setHeader];
    //调用设置表尾的方法
    [self setFooter];
    //获取json数据
    [self loadJsonData];
  
}
/* 获取json数据 */
-(void)loadJsonData{
    [DBJIllTypeModel loadNewsDataWithURLStr:self.urlNunber.urlStr numberId:self.urlNunber.number success:^(NSArray *newsList) {
        self.jsonList=newsList;
        NSLog(@"%@",self.jsonList);
        NSLog(@"self.js%ld",self.jsonList.count);
        [self.tableView.mj_header endRefreshing];
        //刷新数据
        [self.tableView reloadData];
    } failed:^(NSError *error) {
        NSLog(@"error");
    }];
}


/* 设置表头 */
-(void)setHeader{
    __weak typeof(self) weakSelf = self;
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [NSThread sleepForTimeInterval:1.5];
        [weakSelf.tableView.mj_header endRefreshing];
        [DBJTools dbjShowSVSuccessTitle:@"加载完成" andTime:0.8];
    }];
}
//-(void)refreshUpOrDown
//{
//    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
//    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
//    [SVProgressHUD setBackgroundColor:DBJColor];
//    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
//    [SVProgressHUD setMinimumDismissTimeInterval:1.0];
//    
//    [SVProgressHUD showSuccessWithStatus:@"刷新完成"];
//}

- (void)loadNewData{
    
}
/*设置表尾*/
-(void)setFooter{
    __weak typeof(self) weakSelf = self;
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        [NSThread sleepForTimeInterval:1.5];
        [weakSelf.tableView.mj_footer endRefreshing];
        [DBJTools dbjShowSVSuccessTitle:@"加载完成" andTime:0.8];
    }];
}
- (void)loadMoreData{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark -实现数据源方法
/* 返回行数 */
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.jsonList.count;
}

/* 返回单元格 */
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"MinceCell"];
    if(!cell)
    {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MinceCell"];
         cell.textLabel.text=self.jsonList[indexPath.row].ci3_name;
    }
    
    return cell;
}

#pragma mark -实现代理方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
 
    
    UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
    
    if([self.delegate respondsToSelector:@selector(sendMinceWithCell:WithTextStr:)]){
        
        [self.delegate sendMinceWithCell:self WithTextStr:cell.textLabel.text];
    }
    
    
    [self.navigationController popViewControllerAnimated:YES];
}

@end
